﻿#ifdef WIN32
#pragma execution_character_set("utf-8")
#endif

#ifndef DMAINVIEWCONTROLLER_H
#define DMAINVIEWCONTROLLER_H

#include <QObject>

#include "DHeader.h"
#include "DMainView.h"

class DAddHomeworkView;
class DMainViewController : public QObject
{
    Q_OBJECT
public:
    explicit DMainViewController(QObject* parent = nullptr);

    void setMainWindow(DMainView* window)
    {
        m_mainWindow = window;
        connect(m_mainWindow->getTreeWgt(),
                SIGNAL(itemChanged(QTreeWidgetItem*, int)), this,
                SLOT(onTreeItemChanged(QTreeWidgetItem*, int)));

        connect(m_mainWindow, &DMainView::signalQuery, this,
                &DMainViewController::slotQuery);

        connect(m_mainWindow, &DMainView::signalAdd, this,
                &DMainViewController::slotAdd);
    }

    void loadTreeWgt();

private:
    void showHomeworkDetail(DUIHomeworkItem item);
    std::vector<DAddHomework> getAddData(const QDate& dt, IDHomeworkType type);

public slots:
    void slotSubmit(QDate dt, IDHomeworkType type,
                    std::vector<DAddHomework> vecAdd);
    void slotQuery();
    void slotAdd();
    void slotFresh();
    void onTreeItemChanged(QTreeWidgetItem* item, int column);

private:
    DMainView* m_mainWindow = nullptr;
    DAddHomeworkView* m_addHomeworkView = nullptr;
};

#endif  // DMAINVIEWCONTROLLER_H
